import Vue from 'vue'
import VueRouter from 'vue-router'
import Index from "@com/Index/index.vue"
import Exchange from "@com/Exchange/index.vue"
import Account from "@com/Account/index.vue"
import Record from "@com/Record/index.vue"
import Chat from "@com/Chat/index.vue"

// 使用路由插件
Vue.use(VueRouter)

// 设置路由
const routes = [
  { path: '/', component: Index },
  { path: "/incomeExchange", component: Exchange },
  { path: "/incomeExchange/:id", component: Exchange },
  { path: "/benefits", component: Account },
  { path: "/record", component: Record },
  { path: "/chat", component: Chat }
]

let router = new VueRouter({
  mode: 'hash',
  routes
})

// 每次跳转防止滚动位置不对
router.afterEach((to, from) => {
  let bodySrcollTop = document.body.scrollTop
  if (bodySrcollTop !== 0) {
    document.body.scrollTop = 0
    return
  }
  let docSrcollTop = document.documentElement.scrollTop
  if (docSrcollTop !== 0) {
    document.documentElement.scrollTop = 0
  }
})

export default router
